﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Web;
using OpenWaves.ActivityFeed.Web.Handler;
using System.Diagnostics.CodeAnalysis;

namespace OpenWaves.ActivityFeed.Web.Modules
{
    public class ExtendedApiModule : RestModule
    {
        public ExtendedApiModule(IActivityFeedService activityFeedService, IUserIdentityProvider identityProvider, IUserProfileProvider userProfileProvider)
        {
            Contract.Requires<ArgumentNullException>(activityFeedService != null);
            Contract.Requires<ArgumentNullException>(userProfileProvider != null);
            Contract.Requires<ArgumentNullException>(identityProvider != null);

            var extendedApiMethodRegistrationProvider = ServiceLocator.Resolve<IExtendedApiMethodRegistrationProvider>();
            var apiPostMethods = extendedApiMethodRegistrationProvider.GetApiPostMethods();
            foreach (var postMethod in apiPostMethods)
            {
                this.Post(postMethod.Path, postMethod.Action);
            }
        }
    }

    [DefaultImplementation(typeof(ExtendedApiMethodRegistrationProvider))]
    public interface IExtendedApiMethodRegistrationProvider
    {
        [SuppressMessage("Microsoft.Design", "CA1024:Use properties where appropriate")]
        IEnumerable<ApiAction> GetApiPostMethods();
    }

    internal class ExtendedApiMethodRegistrationProvider:IExtendedApiMethodRegistrationProvider
    {
        public IEnumerable<ApiAction> GetApiPostMethods()
        {
            return Enumerable.Empty<ApiAction>();
        }
    }
}